#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/string.hpp>
#include <iostream>
#include <sstream>

class Person {
private:
    friend class boost::serialization::access;
    
    std::string name_;
    int age_;
    
    // 序列化函数
    template<class Archive>
    void serialize(Archive& ar, const unsigned int version) {
        ar & name_;
        ar & age_;
    }
    
public:
    Person() : name_(""), age_(0) {}
    Person(const std::string& name, int age) : name_(name), age_(age) {}
    
    std::string getName() const { return name_; }
    int getAge() const { return age_; }
};

int main() {
    // 序列化
    std::stringstream ss;
    boost::archive::text_oarchive oa(ss);
    
    Person person("Alice", 25);
    oa << person;
    
    std::cout << "Serialized data: " << ss.str() << std::endl;
    
    // 反序列化
    boost::archive::text_iarchive ia(ss);
    Person restored_person;
    ia >> restored_person;
    
    std::cout << "Restored person: " << restored_person.getName() 
              << ", " << restored_person.getAge() << " years old" << std::endl;
    
    return 0;
}